package com.asiainfo.integration.actions.idam;

import org.apache.log4j.Logger;
import org.springframework.http.HttpStatus;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * Usage:
 *
 * @author Charkey
 * @date 2015/12/23
 */
@WebServlet(urlPatterns = "/idam/test", asyncSupported = true)
public class IDAMTestAction extends HttpServlet {

    public static final Logger INFO_LOG = Logger.getLogger(IDAMTestAction.class);

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        response.setHeader("Content-Type", "text/xml;charset=UTF-8");
        response.getWriter().print(
                "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
                        "   <SOAP-ENV:Body>\n" +
                        "      <SOAP-ENV:Fault>\n" +
                        "         <faultcode>SOAP-ENV:Server</faultcode>\n" +
                        "         <faultstring>This is an operation implementation generated fault</faultstring>\n" +
                        "         <faultactor/>\n" +
                        "         <detail>\n" +
                        "            <ns:readUserException xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ns=\"http://www.jio.ril.com/integration/services/common/IdentityManagement/\" xmlns:ns0=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
                        "               <InternalExceptionElement>\n" +
                        "                  <reason>Element not found</reason>\n" +
                        "                  <code>7000</code>\n" +
                        "                  <details>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                        "&lt;details/></details>\n" +
                        "               </InternalExceptionElement>\n" +
                        "            </ns:readUserException>\n" +
                        "         </detail>\n" +
                        "      </SOAP-ENV:Fault>\n" +
                        "   </SOAP-ENV:Body>\n" +
                        "</SOAP-ENV:Envelope>"
        );
    }
}
